﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class WeightOfMailManagement : System.Web.UI.Page
{
    SqlConnection cnn;
    SqlCommand cmd;
    SqlDataReader dread;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check user login or not
        if (Session["Username"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
            if (Session["RoleName"].ToString() == "Employee")
            {
                Response.Redirect("ValidateUser.aspx");
            }

        cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
        cmd = new SqlCommand("SELECT WeightID, Weight, WeightCharge FROM WeightofMail", cnn);
        dread = cmd.ExecuteReader();
        if (!IsPostBack)
        {
            gvWeight.DataSource = dread;
            gvWeight.DataBind();
        }
        dread.Close();
    }
    protected void gvWeight_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string WID;
        WID = Convert.ToString(e.CommandArgument);

        if (e.CommandName == "WUpdate")
        {
            Response.Redirect("WeightOfMail_Update.aspx?WID=" + WID);
        }

        if (e.CommandName == "WDelete")
        {
            cmd = new SqlCommand("Delete from WeightOfMail where WeightID= '" + WID + "'", cnn);
            dread = cmd.ExecuteReader();
            pageload();
        }
    }

    protected void pageload()
    {
        dread.Close();
        cmd = new SqlCommand("SELECT * FROM WeightOfMail", cnn);
        dread = cmd.ExecuteReader();
        gvWeight.DataSource = dread;
        gvWeight.DataBind();
    }

}